package net.csiit.platform.codeguard.classloader;

import java.net.URL;
import java.util.Set;

/**
 * @author adam
 * @date 2020/7/2
 */
public class DecryptSpringBootClassLoader extends DecryptClassLoader {

    public DecryptSpringBootClassLoader(URL[] urls, ClassLoader parent, Set<String> decryptPackages, String decryptKey) {
        super(urls, parent, decryptPackages, decryptKey);
    }

    public DecryptSpringBootClassLoader(URL[] urls, Set<String> decryptPackages, String decryptKey) {
        super(urls, decryptPackages, decryptKey);
    }

    @Override
    protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
        Class<?> cls = null;
        if (CodeGuardConfiguration.isInBasePackage(name)) {
            cls = super.findClass(name);
            if (cls != null && resolve) {
                resolveClass(cls);
            }
        }

        if (cls == null) {
            cls = super.loadClass(name, resolve);
        }

        return cls;
    }
}
